# export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion)
project_dir=$(pwd)

git submodule update --init --recursive

cd 3rdparty/openssl
mkdir -p build
./Configure --prefix=${project_dir}/3rdparty/openssl/build --openssldir=${project_dir}/3rdparty/openssl/build
make install
cd $project_dir

cd 3rdparty/google-benchmark
mkdir -p build
cd build
cmake -G Ninja -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ../
ninja
cd $project_dir

cd 3rdparty/llvm
git apply ../../genptx.patch
mkdir -p build && cd build && cmake -G Ninja ../llvm \
    -DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \
    -DLLVM_TARGETS_TO_BUILD="X86;ARM;RISCV;NVPTX" \
    -DLLVM_ENABLE_ASSERTIONS=ON \
    -DMLIR_ENABLE_CUDA_RUNNER=ON \
    -DCMAKE_BUILD_TYPE=RELEASE
ninja
cd $project_dir

cd 3rdparty/GmSSL
mkdir -p build && cd build && cmake -G Ninja -DENABLE_BROKEN_CRYPTO=ON -DCMAKE_INSTALL_PREFIX=./install ..
ninja && ninja install
cd $project_dir
